<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
	<head>
		<base href="<%=basePath %>">
		<meta charset="utf-8">
		<title>物流订单系统</title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<meta http-equiv="X-UA-Compatible" content="ie=edge">
		<link rel="stylesheet" href=css/bootstrap.min.css>
		<link rel="stylesheet" href=css/bootstrap-table.min.css>
	</head>
	<body >
		<%@include file="/header.jsp" %>
		<div class="container">
		<h1>用户订单列表</h1>
		<hr />
		<table id="orderList"
            	data-url="order/list" data-id-field="id" data-side-pagination="server" 
            	data-method="post" data-content-type="application/x-www-form-urlenorderd; charset=UTF-8"
            	data-pagination="true" data-page-list="[10, 25, 50, 100, ALL]" data-page-size="10"
            	data-show-columns="true" data-show-refresh="true"  data-show-export="true" data-toolbar="#toolbar">
                 <thead>
                     <tr>
                     	<th data-field="state" data-checkbox="true"></th>
                        <th data-field="id">编号</th>
                        <th data-field="start">起点</th>
                        <th data-field="dest">目的地</th>
                        <th data-field="orderDate">下单日期</th>
                        <th data-field="users.name">下单用户</th>
                        <th data-field="carType.name">所需车型</th>
                        <th data-field="distance">总公里数</th>
                        <th data-field="orderPrice">金额</th>
                        <th data-formatter="operateFormatter">操作</th>
                     </tr>
                 </thead>
             </table>
             <script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
             <script type="text/javascript" src="js/bootstrap.min.js"></script>
             <script type="text/javascript" src="js/bootstrap-table.min.js"></script>
             <script type="text/javascript" src="js/bootstrap-table-zh-CN.min.js"></script>
             <script type="text/javascript">
		var $table = $("#orderList");
		$table.bootstrapTable({
			queryParams: function(params){
				params["name"] = $("#orderName").val();
				params["language.id"] = $("#language").val();
				return params;
			}
		});
		//自定义操作列
		function operateFormatter(value, row, index) {
			
			return "	<a class='btn btn-primary' href='order/view?id="+row.id+"'>查看详情</a>&nbsp;&nbsp;<a class='btn btn-success' href='order/jiedan?id="+row.id+"'>立即抢单</a>";
        }

		function shareCode(orderId,state){
			console.log(orderId + " " + state);
			if(state == false){
				if(confirm("确定要共享代码吗？")){
					$.post("order/share",{id:orderId, state:1},function(){
						$table.bootstrapTable("refresh");
					});
				}
			}else{
				if(confirm("确定要取消共享代码吗？")){
					$.post("order/share",{id:orderId, state:0},function(){
						$table.bootstrapTable("refresh");
					});
				}
			}
		}
		
		function searchInfo(){
			$table.bootstrapTable("refresh");
		}

		/**
		 * 删除单条数据
		 * @param url 删除数据的服务端地址
		 * @param id 要删除的数据编号
		 */
		function deleteRecord(url, id) {
			if(confirm("确定要删除该代码吗？")){
				$.post(url, {
					"id" : id
				}, function(data) {
					$table.bootstrapTable("refresh");
				});
			}
		}
				
	</script>
		</div>
	</body>
</html>
